package com.deyang.mycommon.application;

import android.app.Activity;
import android.app.Application;

import com.deyang.mycommon.entity.TokenInfo;
import com.deyang.mycommon.entity.UserInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王德阳
 * @data 创建时间: 2017/11/14 0014
 * @Description
 */
public class MyApplication extends Application {

    private static MyApplication application;
    private List<Activity> openActivityList;

    private UserInfo userInfo;
    private TokenInfo tokenInfo;

    private ApplicationLoader loader;

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        openActivityList = new ArrayList<>();
        loader = new ApplicationLoader(application);

        loader.initToasty();

        loader.initGSY();
    }

    public TokenInfo getTokenInfo() {
        return tokenInfo;
    }

    public void setTokenInfo(TokenInfo tokenInfo) {
        this.tokenInfo = tokenInfo;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    public static MyApplication getApplication() {
        return application;
    }

    public List<Activity> getOpenActivityList() {
        return openActivityList;
    }

    /**
     * 关闭所有的activity
     */
    public void finishAllActivity() {
        List<Activity> openActivityList = this.getOpenActivityList();
        for (Activity a : openActivityList) {
            a.finish();
        }
    }
}
